/*
 * Copyright (c) 2007 The Trustees of Indiana University. All rights reserved.
 * IU CSCI B534 Distributed Systems 2007-02-01 http://www.cs.indiana.edu/classes/b534
 */

package edu.indiana.cs.b534.torrent.struct;

import edu.indiana.cs.b534.torrent.TString;

import java.util.Comparator;

public class TStringComparator implements Comparator<TString> {

    public int compare(TString o1, TString o2) {
        if(o1 == o2) return 0;
        if(o1 == null) return -1; // o2 was not null because of #1
        else
            if(o2 == null) return -1; // o1 was not null because of #1
        String s1 = o1.getValue(), s2 = o2.getValue();
        if(s1 == s2) return 0;
        if(s1 == null) return -1; // s2 was not null because of #1
        else
            if(s2 == null) return -1; // s1 was not null because of #1

        return s1.compareTo(s2);
    }
}

